#include "Game.h"

Game* Game::m_Instance = 0;

Game::Game(void)
{
	m_WorldMap = 0;
}

Game::~Game(void)
{
	Shutdown();
}

void Game::Initialize(void)
{
	m_WorldMap = 0;
	m_WorldWidth = 11;
	m_WorldHeight = 11;
	BuildMap();
}

void Game::Update(void)
{

}

bool Game::Input(void)
{
	return true;
}

void Game::Render(void)
{

}

void Game::Shutdown(void)
{
	if( m_WorldMap )
	{
		delete [] m_WorldMap;
		m_WorldMap = 0;
	}
}

void Game::BuildMap(void)
{
	if( m_WorldMap )
		delete [] m_WorldMap;

	m_WorldMap = new int[m_WorldWidth*m_WorldHeight];

	for(int iter = 0; iter < m_WorldWidth*m_WorldHeight; iter++)
	{
		m_WorldMap[iter] = 0;
	}
}

Game* Game::GetInstance(void)
{
	if( !m_Instance )
		m_Instance = new Game();

	return m_Instance;
}

// Accessors section, put them here and everything else above
int Game::GetWorldMapValue(const int x, const int y)
{
	if( m_WorldMap )
	{
		int position = y * m_WorldWidth + x;
		return m_WorldMap[position];
	}

	return -1;
}

int Game::GetWorldWidth(void)
{
	return m_WorldWidth;
}

int Game::GetWorldHeight(void)
{
	return m_WorldHeight;
}

// Mutators section, put them here and everything else above
void Game::SetWorldMap(const int x, const int y, const int Value)
{
	int position = y * m_WorldWidth + x;
	
	if( m_WorldMap )
		m_WorldMap[position] = Value;
}

void Game::SetWorldWidth(const int Width)
{
	m_WorldWidth = Width;
}

void Game::SetWorldHeight(const int Height)
{
	m_WorldHeight = Height;
}